<?php
//获取微信返回值
foreach ($_GET as $key=>$value)  
{
	if($key == "transaction_id"){
            $transaction_id_value = $value;
    }
    if($key == "out_trade_no"){
        $out_trade_no_value = $value;
    }
    if($key == "attach"){
        $attach = $value;
        $oName = split("#", $attach);
        $cartId = $oName[0];
        $jq_openid = $oName[1];
        $courtDisplayName = $oName[2];
        $date = $oName[3];
        $startTime = $oName[4];
        $endTime = $oName[5];
        $courtAddress = $oName[6];
        $Money = $oName[7];
    }
    logger("Key: $key; Value: $value");
}
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$userOpenid = $postObj->OpenId;
logger($postStr);
$url = "http://stage.billyn.net/index.php/public/WeChatMeta?transaction_id_value=".$transaction_id_value."&out_trade_no_value=".$out_trade_no_value."&cartId=".$cartId."&userOpenid=".$userOpenid."&jq_openid=".$jq_openid."&courtDisplayName=".$courtDisplayName."&date=".$date."&startTime=".$startTime."&endTime=".$endTime."&courtAddress=".$courtAddress."&Money=".$Money;
 if (isset($_GET)){
    echo "success";//反馈微信服务器，此语句需要在前，避免微信重复发送数据
    https_request($url);
}

//日志记录
function logger($log_content)
{
    $max_size = 100000;
    $log_filename = "log.xml";
    if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);}
    file_put_contents($log_filename, $log_content."\r\n", FILE_APPEND);
}
//http请求
function https_request($url, $data = null)
{
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
	if (!empty($data)){
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
	}
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$output = curl_exec($curl);
	curl_close($curl);
	return $output;
} 
?>

